package com.aaa.mbs.controller;

import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.Result;
import com.aaa.mbs.entity.Order;
import com.aaa.mbs.service.OrderService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (Order)表控制层
 *
 * @author makejava
 * @since 2020-12-05 14:23:59
 */
@RestController
@RequestMapping("order")
public class OrderController {

    /**
     * 服务对象
     */
    @Resource
    private OrderService orderService;
    /**
     * 操作日志统计展示
     * @param yearMonth
     * @return
     */
    @GetMapping("LoginLogShowByMonth")
    public Result LoginLogShowByMonth(String yearMonth) {
        return orderService.LoginLogShowByMonth(yearMonth);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("通过主键查询单条数据")
    public Order selectOne(Integer id) {
        return this.orderService.queryById (id);
    }

    /**
     * 查询所有分页加条件查询
     *
     * @param pageNo   第几页
     * @param pageSize 每页显示数量
     * @param order    实体
     * @return Result
     */
    @PostMapping("queryAll")
    @ApiOperation("查询所有分页加条件查询")
    public Result queryAll(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody Order order) {
        return this.orderService.queryAll (pageNo, pageSize, order);
    }
    /**
     * 查询所有分页加条件查询
     *
     * @param pageNo   第几页
     * @param pageSize 每页显示数量
     * @param map    实体
     * @return Result
     */
    @PostMapping("queryAllMap")
    @ApiOperation("联合条件查询")
    public Result queryAllMap(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody Map map) {
        return this.orderService.queryAllMap (pageNo, pageSize, map);
    }

    /**
     * 根据ID删除
     *
     * @param id id
     * @return Result
     */
    @DeleteMapping("deleteById")
    @ApiOperation("根据ID删除")
    public Result deleteById(Integer id) {
        return new Result (ReturnStatus.SUCCESS.getReturnCode (),
                ReturnStatus.SUCCESS.getReturnMsg (), this.orderService.deleteById (id));
    }

    /**
     * 更新
     *
     * @param @param order 实例对象
     * @return Result
     */
    @PutMapping("update")
    @ApiOperation("更新")
    public Result update(@ApiParam("更新json数据") @RequestBody Order order) {
        return new Result (ReturnStatus.SUCCESS.getReturnCode (),
                ReturnStatus.SUCCESS.getReturnMsg (), this.orderService.update (order));
    }

    /**
     * 添加
     *
     * @param @param order 实例对象
     * @return Result
     */
    @PostMapping("insert")
    @ApiOperation("添加")
    public Result insert(@ApiParam("添加json数据") @RequestBody Order order) {
        return new Result (ReturnStatus.SUCCESS.getReturnCode (),
                ReturnStatus.SUCCESS.getReturnMsg (), this.orderService.insert (order));
    }

    @GetMapping("queryByTime")
    @ApiOperation("获取租出的，或者预约的所有汽车id、开始时间、结束时间")
    public Result queryByTime(){
        return this.orderService.queryByTime();
    }
}